#! /usr/bin/perl

package CGI::FOGE2::StatusRSS;
use diagnostics;
diagnostics::enable();
use strict;

use XML::RSS;
use CGI;
use CGI::FOGE2;
use CGI::FOGE2::FormStats;
use CGI::FOGE2::Msg;

=head1 NAME

StatusRSS -- an RSS feed generator that reports on the state of a Form

=head1 DESCRIPTION

To obtain a report on an enquiry, ask this enquiry with an action 
equals to 'StatusRSS', it will deliver as result an RSS 1.0 feed
reporting some facts about the enquiry. This action is offered
by default, no need to declare it in the form for now.

The produced RSS feed may be watched so progress on the enquiry may be
monitored with some news aggregator or syndicated news system.

=head1 BUG

Design a better, more informative, report.

=cut

sub generate_status {
    my ($form) = @_;
    my $stat = new CGI::FOGE2::FormStats();
    $stat->setform($form);
    my $rss = new XML::RSS(version => '1.0');
    $rss->channel(
                  title       => $form->{title},
                  link        => CGI::url(),
                  #description => msg->rss_description,
                  description => 'Enquiry report',
                  syn => {
                      updatePeriod     => "hourly",
                      updateFrequency  => "1",
                      updateBase       => "1901-01-01T00:00+00:00",
                  },
                  );
    $rss->add_item(
                   title       => "Report",
                   link        => CGI::url(),
                   description => "Answers: " . $stat->get_answers_number(),
                   );
    print CGI::header(-type    => 'text/xml',
                      -expires => '+1h');
    print $rss->as_string;
}

1;

# end of StatusRSS.pm
